package com.digital.herbarium.service;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.digital.herbarium.Entity.AboutUs;
import com.digital.herbarium.Exception.CustomException;
import com.digital.herbarium.Mapper.AboutUsMapper;
import com.digital.herbarium.Util.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AboutUsService {

    @Autowired
    AboutUsMapper aboutUsMapper;

    public List<AboutUs> getAboutUsInfo(AboutUs aboutUs){
        return aboutUsMapper.getAboutUsInfo(aboutUs);
    }


    public void   addAboutUsInfo(AboutUs aboutUs){
        aboutUs.setState(1);
        aboutUs.setCreatetime(TimeUtil.getNow());
        aboutUsMapper.addAboutUsInfo(aboutUs);
    }

    public void editAboutUsInfo(AboutUs aboutUs){
        delAboutUsInfo(aboutUs.getId().toString());
        addAboutUsInfo(aboutUs);

    }

    public void delAboutUsInfo(String id){
        if (StrUtil.hasEmpty(id) || StrUtil.hasBlank(id)) {
            throw new CustomException(400, "缺少信息id");
        }
        String[] strArr = id.split(",");
        Long[] ids = Convert.toLongArray(strArr);
        aboutUsMapper.delAboutUsInfo(ids);
    }

}
